package com.biz.primus.ms.tms.dao.ro;

import com.biz.primus.base.redis.annotation.Ro;
import com.biz.primus.base.redis.annotation.RoSortedSet;
import com.biz.primus.base.redis.bean.BaseRedisObject;
import org.apache.commons.lang3.StringUtils;

@Ro(key = "upgrade")
@RoSortedSet(key = "list", score = "id")
public class UpgradeRo extends BaseRedisObject<Long> {
    private static final long serialVersionUID = -2139458212498164922L;


    private String os;
    private boolean force = false;
    private String version;
    private String info;
    private String url;
    private String md5;
    private boolean inhourse = false;

    private boolean need = true;


    public static long versionToScore(String version) {
        if (StringUtils.isNotBlank(version)) {
            if (version.indexOf(".") > 0) {
                String[] arr = version.split("\\.");
                if (arr.length == 3) {
                    return Long.parseLong(arr[0]) * 1000000 + Integer.parseInt(arr[1]) * 1000
                            + Integer.parseInt(arr[2]);
                }
            } else {
                return Long.parseLong(version);
            }
        }
        return 0;
    }

    public long versionToScore() {
        return versionToScore(version);
    }


}
